<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>后台管理系统</title>
    <meta name="author" content="BaiYY"/>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="renderer" content="webkit">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/bootstrap.min.css"/>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/bootstrap-datetimepicker.min.css"/>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/Font/css/font-awesome.min.css"/>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/index.css"/>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/pages.css"/>
    <script type="text/javascript" src="__PUBLIC__/admin/js/jquery.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/js/index.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/js/time.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/js/pages.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
</head>
<body>
    <div class="right-sidebar" style="max-width: 1200px">
        <section class="table-responsive" style="margin-bottom: 0">
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th>游戏ID</th>
                    <th>微信昵称</th>
                    <th>房卡张数</th>
                    <th id="coinNum">{:L(GAME_COUN_NUM)}</th>
                    <th>创建时间</th>
                </tr>
                </thead>
                <tbody id="dataList"></tbody>
            </table>
        </section>
        <div id="playerPage" style="margin: 10px auto">
            <a href="javascript:void(0)" id="prev">上一页</a>
            <a href="javascript:void(0)" id="page"></a>
            <a href="javascript:void(0)" id="next">下一页</a>
            <span>一共</span>
            <a href="javascript:void(0)" id="totalPage"></a>
            <span>页</span>
        </div>

        <div>
            <p><strong>说明</strong></p>
            <p>根据输入的时间段导出相对应的数据</p>
            <div class="form-group">
                <label for="start_time">开始时间</label>
                <input type="text" class="form-control" id="start_time" name="start_time" data-date-format="yyyy-mm-dd hh:ii:ss">
            </div>
            <div class="form-group">
                <label for="end_time">结束时间</label>
                <input type="text" class="form-control" id="end_time" name="end_time" data-date-format="yyyy-mm-dd hh:ii:ss">
            </div>
            <div style="margin: 10px auto;" id="exports" ><a onclick="handel(this)" class="btn btn-primary">数据导出excel</a></div>
        </div>
    </div>
    <script type="text/javascript">
        $(function () {
            var coinNum = $.trim($("#coinNum").text());
            if(coinNum == 'GAME_COUN_NUM' || coinNum == '') {
                $("#coinNum").hide();
            }
            $( "#start_time" ).datetimepicker({
                language: 'zh-CN',
                autoclose: 1,
                todayHighlight: 1,
                weekStart: 1,
                startDate: 0
            });
            $( "#end_time" ).datetimepicker({
                language: 'zh-CN',
                autoclose: 1,
                todayHighlight: 1,
                weekStart: 1,
                startDate: 0
            });
            $.ajax({
                type:"post",
                url:"{:U('Admin/Main/playersMore')}",
                success:function(data) {
//                    console.log(data);
                    var count = Math.ceil(data.count/10);
                    if(data != 'error') {
                        var str = '';
                        for(var i=0;i<data.arr.length;++i) {
                            var time = getLocalTime(data.arr[i].info.createTime);
                            if(coinNum == 'GAME_COUN_NUM' || coinNum == '') {
                                str += "<tr><td class='user_id'>"+data.arr[i]._id+"</td><td>"+data.arr[i].info.name+"</td><td>"+data.arr[i].status.coin+"</td><td>"+time+"</td></tr>";
                            }else{
                                str += "<tr><td class='user_id'>"+data.arr[i]._id+"</td><td>"+data.arr[i].info.name+"</td><td>"+data.arr[i].status.card+"</td><td>"+data.arr[i].status.coin+"</td><td>"+time+"</td></tr>";
                            }
                        }
                        $("#dataList").html(str);
                        $("#totalPage").text(count);
                        $("#page").text(1);
                    }
                }
            })
        });
        $("#prev").on("click",function (ev) {
            var page = $.trim($("#page").text());
            if(page == 1) {
                page = 1;
                return false;
            }else if($("#page").text() > 1) {
                page = page - 1;
            }
            var start = $("#dataList tr:first").find("td.user_id").text();
            var action = -1;
            $.ajax({
                type:"post",
                url:"{:U('Admin/Main/playersMore')}",
                dataType:"json",
                data:{"start":start,"action":action,"page":page},
                success:function(data) {
                    if(data != 'error') {
                        var str = '';
                        for(var i=0;i<data.arr.length;++i) {
                            str += "<tr><td class='user_id'>"+data.arr[i]._id+"</td><td>"+data.arr[i].info.name+"</td><td>"+data.arr[i].status.card+"</td><td>"+data.arr[i].status.coin+"</td><td>"+getLocalTime(data.arr[i].info.createTime)+"</td></tr>";
                        }
                        $("#dataList").html(str);
                        $("#page").text(page);
                    }
                }
            });

        });
        $("#next").on("click",function (e) {
            var page = $.trim($("#page").text());
            page = ++page;
            var totalPage = $.trim($("#totalPage").text())/1;
            if(page > totalPage) {
                return false;
            }
            var start = $("#dataList tr:last").find("td.user_id").text();
            var action = 1;
            $.ajax({
                type:"post",
                url:"{:U('Admin/Main/playersMore')}",
                dataType:"json",
                data:{"start":start,"action":action,"page":page},
                success:function(data) {
                    if(data != 'error') {
                        var str = '';
                        for(var i=0;i<data.arr.length;++i) {
                            str += "<tr><td class='user_id'>"+data.arr[i]._id+"</td><td>"+data.arr[i].info.name+"</td><td>"+data.arr[i].status.card+"</td><td>"+data.arr[i].status.coin+"</td><td>"+getLocalTime(data.arr[i].info.createTime)+"</td></tr>";
                        }
                        $("#dataList").html(str);
                        $("#page").text(page);
                    }
                }
            })
        });
        function handel(This) {
            var start_time = new Date($("#start_time").val()).getTime()/1000;
            var end_time = new Date($("#end_time").val()).getTime()/1000;

            if(start_time == '' || end_time == '') {
                alert("导出数据的时间不能为空!");
                window.location.href="{:U('Admin/Main/logExpend')}";
                return false;
            }
            if(start_time > end_time && start_time == end_time) {
                alert("请注意时间的先后顺序！");
                window.location.href="{:U('Admin/Main/logExpend')}";
                return false;
            }
            $(This).attr('href',"{:U('Admin/Main/userInfoExport')}?start_time="+start_time+"&end_time="+end_time);
        }
    </script>
</body>
</html>